package com.administrator.customviewtest;

import android.graphics.PointF;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.BounceInterpolator;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.EditText;
import android.widget.Toast;

import com.administrator.customviewtest.annotation.MethodInfo;
import com.administrator.customviewtest.reflex.Test1;
import com.administrator.customviewtest.successview.SwipeMenu;
import com.administrator.customviewtest.successview.CurveChartView;
import com.administrator.customviewtest.view.test.TestView22;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ThreadPoolExecutor;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "TAG____Activity4";
    private RecyclerView recyclerView;
    private CommonAdapter<String> adapter;
    private List<String> data = Arrays.asList("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21");

    @MethodInfo(
            author = "ss",
            date = "fdsf",
            version = 2)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.e("ssssss", "decorview应该是framelayout:" + getWindow().getDecorView().getClass().getName());
        Log.e("ssssss", "decorview的子view的数量应该是1，他的子view的类型应该是linearlayout:" + ((ViewGroup) getWindow().getDecorView()).getChildCount() + " " + ((ViewGroup) getWindow().getDecorView()).getChildAt(0).getClass().getName());
        Log.e("ssssss", "linearlayout中第一个view应该是title:actionbar ：" + ((ViewGroup) ((ViewGroup) getWindow().getDecorView()).getChildAt(0)).getChildAt(0).getClass().getName() + "  " + ((ViewGroup) ((ViewGroup) getWindow().getDecorView()).getChildAt(0)).getChildAt(1).getClass().getName());
        Log.e("ssssss", "decorview的contentview:" + ((ViewGroup) ((ViewGroup) ((ViewGroup) getWindow().getDecorView()).getChildAt(0)).getChildAt(1)).getChildAt(0).getClass().getName());
        recyclerView = ((RecyclerView) findViewById(R.id.rv));
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
        adapter = new CommonAdapter<String>(this, R.layout.item_test2, data) {
            @Override
            protected void convert(final ViewHolder holder, final String s, final int position) {
                holder.setText(R.id.tv, s);
                holder.setOnClickListener(R.id.tv_del, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        SwipeMenu.closeMenu();
                        Toast.makeText(MainActivity.this, "删除" + position, Toast.LENGTH_SHORT).show();
                    }
                });
                holder.setOnClickListener(R.id.tv_edit, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        SwipeMenu.closeMenu();
                        Toast.makeText(MainActivity.this, "编辑" + position, Toast.LENGTH_SHORT).show();
                    }
                });
            }
        };
        recyclerView.setAdapter(adapter);

        Test1 test1 = new Test1();

        try {
            Field field = test1.getClass().getDeclaredField("test2");
            field.setAccessible(true);
            Object test2 = field.get(test1);
            if (test2 == null) {
                Log.e("ssss", "null");
            }
            ((Test1.Test2) test2).setJ(3);
            Log.e("ssss", ((Test1.Test2) test2).getJ() + "");
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
            Log.e("ssss", "error1");
        } catch (IllegalAccessException e) {
            Log.e("ssss", "error2");
            e.printStackTrace();
        }


    }
        public boolean Find(int target, int[][] array) {
            int center = array[array.length / 2][array[array.length / 2].length / 2];
            if (target == center) {
                return true;
            } else if (target < center) {
                for (int i = 0; i < array.length / 2; i++) {
                    for (int j = 0; j < array[i][array[i].length / 2]; j++) {
                        if (target == array[i-1][j-1]) {
                            return true;
                        }
                    }
                }
            } else if (target > center) {
                for (int i = array.length / 2; i < array.length; i++) {
                    for (int j = array[i][array[i].length/2]; j < array[i][array[i].length]; j++) {
                        if (target == array[i-1][j-1]) {
                            return true;
                        }
                    }
                }
            }
            return false;
        }
    public void changeModule(View view) {


        switch (view.getId()) {
            case R.id.btn1:
                ((CurveChartView) findViewById(R.id.chart)).setModule(CurveChartView.MODULE.FIVEDAY);
//                TestView22 testView22 = new TestView22();
//                testView22.setDuration(1000);
//                findViewById(R.id.chart).setVisibility(View.VISIBLE);
//                findViewById(R.id.chart).setAnimation(testView22);
//                findViewById(R.id.chart).animate().rotationY(20).setDuration(2000).setInterpolator(new BounceInterpolator()).start();
                break;
            case R.id.btn2:
                ((CurveChartView) findViewById(R.id.chart)).setModule(CurveChartView.MODULE.ONEDAY);
                break;
            case R.id.btn3:
                ((CurveChartView) findViewById(R.id.chart)).setModule(CurveChartView.MODULE.HOUR);

                List<PointF> list = new ArrayList<>();
                PointF pointF1 = new PointF(1, 0.0f);
                PointF pointF2 = new PointF(2.5f, 4.0f);
                PointF pointF3 = new PointF(4f, 9.0f);

                list.add(pointF1);
                list.add(pointF2);
                list.add(pointF3);

                ((CurveChartView) findViewById(R.id.chart)).setPointList(list);
                break;
            case R.id.btn4:
                ((CurveChartView) findViewById(R.id.chart)).setCurrentDay(Integer.parseInt(((EditText) findViewById(R.id.edt)).getText().toString()));
               ((EditText) findViewById(R.id.edt)).setText("");
                break;
        }
    }

    private boolean testa() {
        return false;
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return super.onTouchEvent(event);
    }
}
